package com.haste.controller;

import com.haste.pojo.CommonResult;
import com.haste.pojo.Payment;
import com.haste.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    /**
     *@Author:haste
     *@Description:保存一条记录
     *@Date: 2021/2/5 16:54
     **/
    @PostMapping("/payment/save")
    public CommonResult save(@RequestBody Payment payment){
        Integer result = paymentService.save(payment);
        if (result > 0){
            return new CommonResult(200,"插入成功",result);
        }else {
            return new CommonResult(444,"插入失败",null);
        }
    }

    /**
     *@Author:haste
     *@Description:根据id查询
     *@Date: 2021/2/5 16:55
     **/
    @GetMapping("/payment/detail/{id}")
    public CommonResult<Payment> detail(@PathVariable("id") Long id){
        Payment payment = paymentService.detail(id);
        if (payment != null){
            return new CommonResult(200,"查询成功",payment);
        }else {
            return new CommonResult(444,"查询失败,没有"+id+"这个id的记录",null);
        }
    }

    /**
     *@Author:haste
     *@Description:查询所有
     *@Date: 2021/2/5 16:55
     **/
    @GetMapping("/payment/list")
    public CommonResult list(){
        List<Payment> paymentList = paymentService.list();
        if (paymentList != null){
            return new CommonResult(200,"查询成功",paymentList);
        }else {
            return new CommonResult(444,"查询失败",null);
        }
    }
}
